import {Person, WithBinaryDataType, WithComplexDataType, WithSimpleDataType} from "./interface";
import {TextDecoder, TextEncoder} from "util";

/**
 Created by:
 muhtearjan mehmood مۇختەرجان مەخمۇت (Email: yeganaaa@163.com)
 At 8/20/20 5:31 PM
 */


export async function testWithSimpleData(module: WithSimpleDataType) {
    expect(await module.reverse(true)).toBe(false)
    expect(await module.sum({a: 11, b: 22})).toBe(33)
    expect(await module.sayHello("yeganaaa")).toBe("Hello yeganaaa")
    for (let index = 0; index < 100; index++) {
        expect(await module.counterOnState()).toBe(index)
    }
}
export async function testWithComplexData(module: WithComplexDataType) {
    const obj: Person = {
        name: "yeganaaa",
        birthday: Date.now(),
        email: "yeganaaa@163.com",
        address: {
            city: "Kashgar",
            country: "China"
        },
        contacts: [
            {name: "Phone number", value: "18690134647"},
            {name: "Wechat number", value: "Dream-Labs"},
            {name: "QQ Number", value: "1622180363"},
        ]
    }
    expect(await module.getSelf(obj)).toEqual(obj)
}
export async function testWithBinaryData(module: WithBinaryDataType) {
    const text = "Hello world from DreamRpc framework"
    const data = new TextEncoder().encode(text)
    expect(new TextDecoder().decode(await module.updateImage(data))).toBe(text)
}